//
//  GSSCommunicator.h
//  iGSS
//
//  Copyright 2010 Electronic Business Systems Ltd.
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//

#import <Foundation/Foundation.h>

#import "GSSObject.h"
#import "GSSHome.h"
#import "GSSOthers.h"
#import "GSSTags.h"
#import "GSSGroups.h"
#import "GSSQuery.h"

extern NSString *GSSRootURI;
extern NSString *GSSMetaCachePath;
extern NSString *GSSDataCachePath;

@class GSSOperation;

@interface GSSCommunicator : NSObject {
	NSString *username;
	NSData *token;
    GSSHome *home;
	
	NSOperationQueue *requestQueue;
    NSMutableSet *pendingRequests;
    NSMutableArray *prefetchQueue;
    NSMutableDictionary *objectCache;
}

@property (nonatomic, copy) NSString *username;
@property (nonatomic, retain) NSData *token;

@property (nonatomic, readonly) NSURL *loginURL;
@property (nonatomic, readonly) NSString *homeURI;

@property (nonatomic, readonly) GSSHome *home;
@property (nonatomic, readonly) GSSOthers *others;
@property (nonatomic, readonly) GSSObject *trash;
@property (nonatomic, readonly) GSSTags *tags;
@property (nonatomic, readonly) GSSGroups *groups;

+ (GSSCommunicator *)defaultCommunicator;

- (void)logout;
- (NSString *)generateUniqueName:(NSString *)name withTemplate:(NSString *)template forObject:(GSSObject *)object;

- (GSSObject *)objectWithURI:(NSString *)uri withType:(GSSObjectType)type;

- (void)prefetchObject:(GSSObject *)object;
- (void)updateMetaOfObject:(GSSObject *)object;
- (void)updateMetaOfObject:(GSSObject *)object withDependency:(NSOperation *)dep;
- (void)updateFileObject:(GSSObject *)object;

- (void)setMeta:(NSDictionary *)newMeta ofObject:(GSSObject *)object;
- (void)setName:(NSString *)name ofObject:(GSSObject *)object;
- (void)setVersioned:(BOOL)value ofObject:(GSSObject *)object;
- (void)setReadForAll:(BOOL)value ofObject:(GSSObject *)object;
- (void)setTags:(NSArray *)tags ofObject:(GSSObject *)object;
- (void)setPermissions:(NSArray *)permissions ofObject:(GSSObject *)object;
- (void)moveToTrashObject:(GSSObject *)object;
- (void)restoreFromTrashObject:(GSSObject *)object;
- (void)deleteObject:(GSSObject *)object;

- (void)createFolderNamed:(NSString *)name inFolder:(GSSObject *)folder;
- (void)createFile:(GSSObject *)file withData:(NSData *)data inFolder:(GSSObject *)folder;

- (GSSQuery *)searchFiles:(NSString *)prefix;

- (void)operationFinished:(GSSOperation *)operation;

@end